package com.service.Impl;

import com.dao.SupplierMapper;
import com.entity.Supplier;
import com.service.SupplierService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    public void setSupplierMapper(SupplierMapper supplierMapper) {

        this.supplierMapper = supplierMapper;
    }

    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> list() {
        return supplierMapper.list();
    }


    public boolean add(Supplier supplier){
        boolean result = false;
        try{
            if (supplierMapper.add(supplier) == 1){
                result = true;
                //测试事务回滚时，打开注释
                //throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    public int update(Supplier supplier){
        int result = 0;
        try {
            if (supplierMapper.update(supplier) > 0){
                System.out.println("修改成功！");
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }
}
